package 动态代理;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;

public class MyInvocationHandler implements InvocationHandler {

    private Object target;

    public MyInvocationHandler() {
    }

    MyInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if ("getName".equals(method.getName())) {
            System.out.println("add line 1: Name---------------------");
            System.out.println(Arrays.toString(args));
            Object invoke = method.invoke(target, args);
            System.out.println(method.getName());
            System.out.println("add line 2: Name---------------------");
            return invoke;
        } else {
            System.out.println("add line 1: Age");
            Object invoke = method.invoke(target, args);
            System.out.println("add line 2: Age");
            return invoke;
        }
    }
}
